package BeanUtils.T4;


import org.apache.commons.beanutils.BeanUtils;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class T4 {

    public static void main(String[] args) throws Exception {

        SAXReader sr = new SAXReader();
        Document doc = sr.read(new File("BeanUtils/T4/beans.xml"));
        Element rootElement = doc.getRootElement();
        List<Element> elements = rootElement.elements();
        for (Element element : elements) {
            String className = element.attributeValue("className");
            Class<?> aClass = Class.forName(className);
            Object obj = aClass.newInstance();
            List<Element> proEles = element.elements();
            for (Element proEle : proEles) {
                String name = proEle.attributeValue("name");
                String value = proEle.attributeValue("value");
                BeanUtils.setProperty(obj,name,value);
            }
            System.out.println(obj);
        }



    }
}
